﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PetaPoco;
using Shop.Page.Models;

namespace Shop.Page.Repositories
{
    public class PageAccess
    {
        private Database DB = new Database("ConnString");
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="wpinfo"></param>
        /// <returns></returns>
        public object AddWares(WaresPicture wpinfo)
        {
            return DB.Insert("Shop_HomePictures", "HID", wpinfo);
        }
        /// <summary>
        /// 获取信息
        /// </summary>
        /// <returns></returns>
        public IList<WaresPicture> GetWPInfo()
        {
            Sql sql = Sql.Builder.Append("select * from Shop_HomePictures order by OrderTime desc");
            return DB.Fetch<WaresPicture>(sql);
        }
        /// <summary>
        /// 根据ID获取信息
        /// </summary>
        /// <param name="HID"></param>
        /// <returns></returns>
        public WaresPicture GetWPInfoByHID(int HID)
        {
            Sql sql = Sql.Builder.Append("select * from Shop_HomePictures where HID = @0",HID);
            return DB.FirstOrDefault<WaresPicture>(sql);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="wpinfo"></param>
        /// <returns></returns>
        public int UpdatePage(WaresPicture wpinfo)
        {
            Sql sql = Sql.Builder.Append("update Shop_HomePictures set WID = @0,WName = @1,Url = @2 where HID = @3",wpinfo.WID,wpinfo.WName,wpinfo.Url,wpinfo.HID);
            return DB.Execute(sql);
        }
        /// <summary>
        /// 置顶
        /// </summary>
        /// <param name="HID"></param>
        /// <returns></returns>
        public int OrderPage(int HID)
        {
            Sql sql = Sql.Builder.Append("update Shop_HomePictures set OrderTime = getdate() where HID = @0",HID);
            return DB.Execute(sql);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="HID"></param>
        /// <returns></returns>
        public int DelPage(int HID)
        {
            Sql sql = Sql.Builder.Append("delete from Shop_HomePictures where HID = @0",HID);
            return DB.Execute(sql);
        }
    }
}
